<?php defined('SYSPATH') or die('No direct script access.');

/**
 * 户外产品
 * Class Controller_Pc_Api_V2_Outdoor
 */
class Controller_Pc_Api_V2_Outdoor extends Controller_Pc_Api_v2_Base
{
    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_Outdoor
     */
    private $validation;

    /**
     * 服务
     * @var Service_Api_Outdoor
     */
    private $service;

    public function before()
    {
        parent::before();

        // 验证
        $this->validation = Request_Api_V2_Factory::create('outdoor', $this->request_params);

        // 服务
        $this->service = new Service_Api_Outdoor();

        // 返回数据
        $this->result = array('status' => true, 'msg' => '操作成功', 'data' => array());
    }

    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    // 搜索条件
    public function action_query_condition()
    {
        try {
            $this->result['data'] = $this->service->query_condition();
        } catch (Exception $e) {
            $this->result['status'] = false;
            $this->result['msg']    = $e->getMessage();
        }
    }

    // 搜索
    public function action_get_list()
    {
        try {
            $this->validation->query()->check();

            $this->result['data'] = $this->service->search($this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 详情
    public function action_get_detail()
    {
        try {
            $this->validation->get_detail()->check();

            $this->result['data'] = $this->service->info($this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 创建订单
    public function action_add_order()
    {
        try {
            $this->validation->add_order()->check();
            $this->request_params['member_info'] = $this->member_info;
            $this->result['data'] = $this->service->create_order($this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 参与人员
    public function action_join_member()
    {
        try {
            $this->validation->join_member()->check();

            $this->result['data'] = $this->service->join_member($this->request_params['id'], $this->request_params['date']);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 获取套餐
    public function action_get_suit()
    {
        try {
            $this->validation->get_suit()->check();

            $this->result['data'] = $this->service->get_suit($this->request_params);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 合同
    public function action_contract()
    {
        try {
            $this->validation->contract()->check();

            $this->result['data'] = $this->service->contract($this->request_params['id']);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    // 户外活动首页导航
    public function action_nav()
    {
        try {
            $this->validation->nav()->check();

            $this->result['data'] = $this->service->nav($this->request_params['row']);
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    public function action_recent_outdoor()
    {
        try {
            $this->result['data'] = $this->service->recent_outdoor();
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }
}
